package com.central.apps.handler.supplier;

import com.central.app.common.base.BaseHandler;
import com.central.app.service.HandlerService;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

//慎选供应商
@Component
@Slf4j
public class SuppcareHandler extends BaseHandler {
    @Autowired
    private HandlerService handlerService;



    @Override
    public String beforeExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op) throws Exception {
        if ("submit".equals(flowNode.getId())){
            List<Map<String, Object>> bySql = handlerService.findBySql("select application from gq_suppcare where id=" + id);
            Map<String, Object> map = bySql.get(0);
            String application = MapUtils.getString(map, "application");
            List<Map<String, Object>> bySql1 = handlerService.findBySql("select application from gq_selectcarefully where application='" + application + "'");
            if (CollectionUtils.isEmpty(bySql1)){
                return "请添加慎选供方列表相关信息！";
            }
        }

       return super.beforeExcuteFlow(app, id, flowNode, op);
    }
   
}
